package com.lanou.sfu.songforu.music_library_fragment;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.base.BaseFragment;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/27.
 */
public class ArtistDetailFragment extends BaseFragment {
    private View v;
    private String artistId;
    private String artistPic;
    public ArtistDetailSongFragment fragmentSong;
    public ArtistDetailAlbumFragment fragmentAlbum;
    private ImageView imageView;
    private TextView song, album;
    private Drawable text_drawable;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        v = inflater.inflate(R.layout.fragment_artist_detail, null);
        imageView = (ImageView) v.findViewById(R.id.artist_detail_backdrop);
        song = (TextView) v.findViewById(R.id.song);
        album = (TextView) v.findViewById(R.id.album);
        return v;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        text_drawable = getResources().getDrawable(R.mipmap.play_progress);
        text_drawable.setBounds(0, 0, text_drawable.getMinimumWidth(), text_drawable.getMinimumHeight());

        // 给页面设置工具栏
        final Toolbar toolbar = (Toolbar) v.findViewById(R.id.artist_detail_toolbar);
        toolbar.setNavigationIcon(R.mipmap.bt_return_nor);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getFragmentManager().popBackStack();
            }
        });
        // 设置工具栏标题
        CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) v.findViewById(R.id.artist_detail_collapsing_toolbar);
        collapsingToolbar.setContentScrimColor(0xf48852);
        Bundle bundle = getArguments();
        artistId = bundle.getString(getString(R.string.artistID));
        artistPic = bundle.getString(getString(R.string.picUrl));
        if (artistPic != null) {
            Picasso.with(getActivity()).load(artistPic).into(imageView);
        }
        fragmentSong = new ArtistDetailSongFragment();
        Bundle bundle1 = new Bundle();
        bundle1.putString(getString(R.string.id), artistId);
        fragmentSong.setArguments(bundle1);
        fragmentAlbum = new ArtistDetailAlbumFragment();
        fragmentAlbum.setArguments(bundle1);

        getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.artist_detail_replace, fragmentSong).commit();
        song.setCompoundDrawables(null, null, null, text_drawable);
        song.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.artist_detail_replace, fragmentSong).commit();
                song.setCompoundDrawables(null, null, null, text_drawable);
                album.setCompoundDrawables(null, null, null, null);
            }
        });

        album.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.artist_detail_replace, fragmentAlbum).commit();
                album.setCompoundDrawables(null, null, null, text_drawable);
                song.setCompoundDrawables(null,null,null,null);
            }
        });

    }

}
